#ifndef CASKSTATUS_H
#define CASKSTATUS_H

#include <QObject>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QLabel>
#include <QGridLayout>
#include <QGroupBox>
#include <QJsonObject>
#include <QDebug>
#include <QRadioButton>
#include <QJsonArray>
#include <QCheckBox>
#include "Flag1Status.h"

//#include "cnp.hpp"
//#include "SensorParser.h"
#include <QJsonDocument>
#include <QJsonParseError>
#include <QDebug>
#include <QMap>
#include <QLineEdit>
#include <QMutex>
#include"DeviceManager.h"
#include <QSharedPointer>
#include "Flag1Status.h"
#include "Flag2Status.h"


struct SensorData {
    double displacement;
    double velocity;
    double hinge;
    int    lockState;
};


class CaskStatus : public QWidget
{
    Q_OBJECT
public:
    explicit CaskStatus(QWidget *parent = nullptr);
    explicit CaskStatus(const QJsonObject &functionDetails, const QString deviceID,QWidget *parent = nullptr);
    void createCaskStatus(QGroupBox *groupBox, const QJsonObject &functionDetails);
    ~CaskStatus();
    void updateFieldValue(const QString &fieldName, const QString &newValue);
    //void parseSensorData(const QString &jsonString, SensorData &outData);

signals:
        void upSubEvent(const QStringList &evt);
        void colorChanged(const QString &color);

public slots:
    // 绑定节点后
    void attachToNode(QSharedPointer<DeviceNode> node);

private slots:
    void onDataReceived(const QString& content);
    void onEventReceived(const QString& content);

private:
    // 存储字段名称和对应的 QLineEdit 的映射
    QMap<QString, QLineEdit*> fieldLineEdits;
    QList<Flag2Status*> Flag2StatusList;


    //CNPClient* mCaskStatu;
    SensorData mData;
    QMutex mCaskStatuMutex;//互斥鎖
    QString exEventMsg[2];
    //void subCallBack(const CnpMsg &msg);
    void subEventCallBack(const QString& content);//解析时间，框框显示
    void eventStatuCallback(const QString &content);//解析事件，修改颜色
    void upStateColor();//更新状态颜色
    //更改结点架构
     QSharedPointer<DeviceNode> m_node;
     QString currentDevice;
     QString mDeviceID;
     QMap<QString,QString> onceMsg;
     QString lastSteteColor = " ";//上次的状态颜色

};

#endif // CASKSTATUS_H
